package com.gscitysfy.cus.drain.modules.duty.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.gscitysfy.cus.drain.modules.duty.entity.MoperDutyRlRecord;
import com.gscitysfy.cus.drain.modules.duty.mapper.MoperDutyRlRecordMapper;
import com.gscitysfy.cus.drain.modules.duty.service.IMoperDutyRlRecordService;
import com.gscitysfy.cus.drain.utils.DateUtil;
import org.apache.http.util.Asserts;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Administrator
 * @since 2022-03-29 15:06:16
 */
@Service
public class MoperDutyRlRecordServiceImpl extends ServiceImpl<MoperDutyRlRecordMapper, MoperDutyRlRecord> implements IMoperDutyRlRecordService {

    @Override
    public List<MoperDutyRlRecord> listLastMonthDutyRecord(Date planDate) {
        Asserts.notNull(planDate, "planDate");
        Date lastMonth = DateUtil.getLastMonth(planDate);
        Date beginDate = DateUtil.getMonthBeginDate(lastMonth);
        Date endDate = DateUtil.getMonthEndDate(lastMonth);
        return list(
                Wrappers.<MoperDutyRlRecord>lambdaQuery()
                        .ge(MoperDutyRlRecord::getCoamDutyDate, beginDate)
                        .le(MoperDutyRlRecord::getCoamDutyDate, endDate)
        );
    }

    @Override
    public void removeAllCurrentMonthDutyDate(Date planDate) {
        Asserts.notNull(planDate, "planDate");
        Date beginDate = DateUtil.getMonthBeginDate(planDate);
        Date endDate = DateUtil.getMonthEndDate(planDate);
        remove(
                Wrappers.<MoperDutyRlRecord>lambdaQuery()
                        .ge(MoperDutyRlRecord::getCoamDutyDate, beginDate)
                        .le(MoperDutyRlRecord::getCoamDutyDate, endDate)
        );

    }

}
